package com.pwt.controller.basicsetting;

import com.pwt.annotation.Update;
import com.pwt.common.ResultPage;
import com.pwt.entity.MenuSetting;
import com.pwt.model.ComboBoxModel;
import com.pwt.model.MenuType;
import com.pwt.model.TreeModel;
import com.pwt.service.MenuSettingService;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dw
 * @version 1.0.0
 * @date 2021/9/28
 */
@RestController
@Tag(name = "配置子菜单")
public class MenuSettingController {

    private MenuSettingService menuSettingService;

    public MenuSettingController(MenuSettingService menuSettingService) {
        this.menuSettingService = menuSettingService;
    }
    @Hidden
    @GetMapping("/submenu/type")
    @Operation(description = "根据菜单类型查询子菜单类型",summary = "根据菜单类型查询子菜单类型")
    public List<MenuType> getMenuType(@RequestParam @Parameter(description = "1-监控类型，2-逻辑单元测试") Integer type){
        return this.menuSettingService.getMenuType(type);
    }
    @Hidden
    @GetMapping("/process")
    @Operation(description = "获取工序类型",summary = "获取工序类型")
    public List<TreeModel>  getProcess(){
        return this.menuSettingService.getProcess();
    }
    @Hidden
    @GetMapping("/menu-setting")
    @Operation(description = "菜单列表",summary = "菜单列表")
    @Parameters({
            @Parameter(name = "type",description = "菜单类型 1-监控类型，2-逻辑单元测试"),
            @Parameter(name = "prueferName",description = "工序名称"),
            @Parameter(name = "page",description = "当前页"),
            @Parameter(name = "limit",description = "每页展示数")
    })
    public ResultPage<MenuSetting> getMenuSetting(@RequestParam(required = false) Integer type,@RequestParam(required = false) String prueferName, Integer page, Integer limit){
        return this.menuSettingService.getMenuSetting(type,prueferName,page,limit);
    }
    @Hidden
    @GetMapping("/submenu/prueferId")
    @Operation(description = "根据菜单类型，工序id，查询子菜单",summary = "根据菜单类型，工序id，查询子菜单")
    public List<MenuType> getList(@RequestParam @Parameter(name = "type",description = "菜单类型") Integer type,
                                  @RequestParam @Parameter(name = "prueferId",description = "工序id") Integer prueferId){
        return this.menuSettingService.getList(type,prueferId);
    }
    @Hidden
    @PostMapping("/menu-setting")
    @Operation(description = "新增配置菜单",summary = "新增配置菜单")
    public MenuSetting add(@RequestBody MenuSetting menuSetting){
        return this.menuSettingService.add(menuSetting);
    }
    @Hidden
    @PutMapping("/menu-setting")
    @Operation(description = "修改配置菜单",summary = "修改配置菜单")
    public MenuSetting update(@RequestBody @Validated(value = Update.class) MenuSetting menuSetting){
        return this.menuSettingService.add(menuSetting);
    }
    @Hidden
    @DeleteMapping("/delete/{id}")
    @Operation(description = "根据id删除配置",summary = "根据id删除配置")
    public void delete(@PathVariable("id") @Parameter(name = "id",description = "配置id") String id){
        this.menuSettingService.delete(id);
    }
}
